package com.lzx.iteam.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import com.lzx.iteam.R;
import com.lzx.iteam.bean.PayToolsGroupData;
import com.lzx.iteam.util.ImageLoaderInterface;
import com.lzx.iteam.util.StringUtil;
import com.lzx.iteam.widget.RoundImageView;

import java.util.ArrayList;

/**
 * Created with IntelliJ IDEA.
 * **********************************
 * User: zhangshuai
 * Date: 2016年 09月 20日
 * Time: 下午3:29
 *
 * @QQ : 1234567890
 * **********************************
 */
public class PayToolsGroupAdapter extends BaseAdapter {

    private Context mContext;
    private String type;
    private ArrayList<PayToolsGroupData> mData;
    private int mIndex;

    public PayToolsGroupAdapter(Context mContext) {
        this.mContext = mContext;
    }

    public void bindData(String type, ArrayList<PayToolsGroupData> mData){
        this.type = type;
        this.mData = mData;
        notifyDataSetChanged();
    }

    public void updateView(int index){
        this.mIndex = index;
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return mData == null ? 0:mData.size();
    }

    @Override
    public Object getItem(int position) {
        return mData.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null){
            holder = new ViewHolder();
            convertView = LayoutInflater.from(mContext).inflate(R.layout.pay_tools_group_item_layout,null);
            holder.avatar = (RoundImageView) convertView.findViewById(R.id.pay_group_item_avatar);
            holder.groupName = (TextView) convertView.findViewById(R.id.pay_group_item_tv_name);
            holder.groupMsg = (TextView) convertView.findViewById(R.id.pay_group_item_tv_msg);
            holder.imageSelect = (ImageView) convertView.findViewById(R.id.pay_group_item_iv_select);
            convertView.setTag(holder);
        }else{
            holder = (ViewHolder) convertView.getTag();
        }
        PayToolsGroupData data = mData.get(position);
        ImageLoaderInterface.imageLoader.displayImage(data.getGroup_img(),holder.avatar,ImageLoaderInterface.optionHeadImage);
        holder.groupName.setText(data.getGroup_name());

        switch (Integer.parseInt(type)){
            case 0:
                holder.groupMsg.setText(String.format("当前人数上限为%1s人,升级后为%2s人",data.getMember_limit(),data.getMember_limit() + 100));
                break;
            case 1:
                holder.groupMsg.setText(String.format("当前考勤成员上限为%1s人,升级后为%2s人",data.getAttendance_member_limit(),data.getAttendance_member_limit() + 100));
                break;
            case 2:
                holder.groupMsg.setText(String.format("当前连锁店考勤点为%1s个,升级后为%2s个",data.getAttendance_count_limit(),data.getAttendance_count_limit() + 5));
                break;
            case 3:
                if (data.getLegwork_status() == 0){
                    holder.groupMsg.setText("当前未开通外勤签到,升级后开通外勤签到");
                }else if (data.getLegwork_status() == 1){
                    holder.groupMsg.setText("外勤签到已启动");
                }
                break;
        }

        if (position == mIndex){
            holder.imageSelect.setVisibility(View.VISIBLE);
        }else{
            holder.imageSelect.setVisibility(View.GONE);
        }
        return convertView;
    }

    class ViewHolder{
        RoundImageView avatar;
        TextView groupName,groupMsg;
        ImageView imageSelect;
    }
}
